<?php

namespace app\common\model;

use think\Model;

class Post extends Model
{
    protected $table = 'posts';

    protected $autoWriteTimestamp = 'timestamp';


    public function comments()
    {
        return $this->hasMany(Comment::class, 'post_id');
    }

    public function tags()
    {
        return $this->belongsToMany(Tag::class, 'posts_tags', 'tag_id');
    }

    public function hasTag($tagId)
    {
        return $this->tags()->where('pivot.tag_id', $tagId)->find();
    }
}
